﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.OS
{
    public partial class Linux
    {
        /// <summary>
        /// 读取CPU串号
        /// </summary>
        /// <returns></returns>
        public static string ReadCPUSerial()
        {
            var file = "/proc/cpuinfo";
            if (System.IO.File.Exists(file))
            {
                var lines = System.IO.File.ReadAllLines(file, Encoding.UTF8);
                if (lines != null)
                {
                    Array.Reverse(lines);
                    foreach (var line in lines)
                    {
                        if (line.StartsWith("Serial", StringComparison.OrdinalIgnoreCase))
                        {
                            var index = line.IndexOf(':');
                            string txt = "";
                            if (index < line.Length)
                            {
                                txt = line.Substring(index + 1);
                            }

                            var serial = txt.Trim().ToLower();
                        }
                    }
                }
            }
            return null;
        }
    }
}
